/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.orderoid.ejb.domain;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Dahlia
 */
@Entity
@Table(name = "commande")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Commande.findAll", query = "SELECT c FROM Commande c"),
    @NamedQuery(name = "Commande.findByIdCommande", query = "SELECT c FROM Commande c WHERE c.idCommande = :idCommande"),
    @NamedQuery(name = "Commande.findByDateCommande", query = "SELECT c FROM Commande c WHERE c.dateCommande = :dateCommande"),
    @NamedQuery(name = "Commande.findByDateLivraison", query = "SELECT c FROM Commande c WHERE c.dateLivraison = :dateLivraison"),
    @NamedQuery(name = "Commande.findByMontant", query = "SELECT c FROM Commande c WHERE c.montant = :montant")})
public class Commande implements Serializable {
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_commande")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCommande;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_livraison")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateLivraison;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_commande")
    private Integer idCommande;
    @Basic(optional = false)
    @NotNull
    @Column(name = "montant")
    private double montant;
    // @Basic(optional = true)
    // @NotNull
    @Size(min = 0, max = 200)
    @Column(name = "raison_refus")
    private String raisonRefus;
    @JoinTable(name = "tr_commande_menu", joinColumns = {
        @JoinColumn(name = "id_commande", referencedColumnName = "id_commande")}, inverseJoinColumns = {
        @JoinColumn(name = "id_menu", referencedColumnName = "id_menu")})
    @ManyToMany
    private Collection<Menu> menuCollection;
    @JoinTable(name = "tr_commande_produit", joinColumns = {
        @JoinColumn(name = "id_commande", referencedColumnName = "id_commande")}, inverseJoinColumns = {
        @JoinColumn(name = "id_produit", referencedColumnName = "id_produit")})
    @ManyToMany
    private Collection<Produit> produitCollection;
    @JoinColumn(name = "id_statut", referencedColumnName = "id_statut")
    @ManyToOne(optional = false)
    private StatutCommande idStatut;
    @JoinColumn(name = "id_adresse", referencedColumnName = "id_adresse")
    @ManyToOne(optional = false)
    private Adresse idAdresse;
    @JoinColumn(name = "id_client", referencedColumnName = "id_client")
    @ManyToOne(optional = false)
    private Client idClient;
    @JoinColumn(name = "id_restaurant", referencedColumnName = "id_restaurant")
    @ManyToOne(optional = false)
    private Restaurant idRestaurant;

    public Commande() {
    }

    public Commande(Integer idCommande) {
        this.idCommande = idCommande;
    }

    public Commande(Integer idCommande, Date dateCommande, Date dateLivraison, double montant, String raisonRefus) {
        this.idCommande = idCommande;
        this.dateCommande = dateCommande;
        this.dateLivraison = dateLivraison;
        this.montant = montant;
        this.raisonRefus = raisonRefus;
    }

    public Integer getIdCommande() {
        return idCommande;
    }

    public void setIdCommande(Integer idCommande) {
        this.idCommande = idCommande;
    }

    public Date getDateCommande() {
        return dateCommande;
    }

    public void setDateCommande(Date dateCommande) {
        this.dateCommande = dateCommande;
    }

    public Date getDateLivraison() {
        return dateLivraison;
    }

    public void setDateLivraison(Date dateLivraison) {
        this.dateLivraison = dateLivraison;
    }

    public double getMontant() {
        return montant;
    }

    public void setMontant(double montant) {
        this.montant = montant;
    }

    public String getRaisonRefus() {
        return raisonRefus;
    }

    public void setRaisonRefus(String raisonRefus) {
        this.raisonRefus = raisonRefus;
    }

    @XmlTransient
    public Collection<Menu> getMenuCollection() {
        return menuCollection;
    }

    public void setMenuCollection(Collection<Menu> menuCollection) {
        this.menuCollection = menuCollection;
    }

    @XmlTransient
    public Collection<Produit> getProduitCollection() {
        return produitCollection;
    }

    public void setProduitCollection(Collection<Produit> produitCollection) {
        this.produitCollection = produitCollection;
    }

    public StatutCommande getIdStatut() {
        return idStatut;
    }

    public void setIdStatut(StatutCommande idStatut) {
        this.idStatut = idStatut;
    }

    public Adresse getIdAdresse() {
        return idAdresse;
    }

    public void setIdAdresse(Adresse idAdresse) {
        this.idAdresse = idAdresse;
    }

    public Client getIdClient() {
        return idClient;
    }

    public void setIdClient(Client idClient) {
        this.idClient = idClient;
    }

    public Restaurant getIdRestaurant() {
        return idRestaurant;
    }

    public void setIdRestaurant(Restaurant idRestaurant) {
        this.idRestaurant = idRestaurant;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCommande != null ? idCommande.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Commande)) {
            return false;
        }
        Commande other = (Commande) object;
        if ((this.idCommande == null && other.idCommande != null) || (this.idCommande != null && !this.idCommande.equals(other.idCommande))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.orderoid.ejb.domain.Commande[ idCommande=" + idCommande + " ]";
    }

    
}
